clear all;

% For Table 1, all magnitudes are computed analytically, using the properties
% of the uniform distribution (explicit expressions for all order
% statistics) and the fact that in the equilibrium of GSP with a reserve
% price, for a given profile of values, the revenue is the same as in VCG 
% with the same reserve price - and VCG has a convenient form. We then add
% up the cases for which there are zero bidders above the reserve price, one
% bidder, two bidders, etc. 

% First row of the table

r20 = 1/3

r2opt = 1/4*0 + 1/2*0.5 + 1/4*2/3

impact2 = r2opt/r20 - 1

% Second row

r60 = 5/7

r6opt = (1/2)^6 * (1*0 + 6*0.5 + 15*(0.5 + 0.5*1/3) + 20*(0.5 + 0.5*2/4) + 15*(0.5 + 0.5*3/5) + 6*(0.5 + 0.5*4/6) + 1*(0.5 + 0.5*5/7))

impact6 = r6opt/r60 - 1

% Third row

rGSP20 = 0.3*r20

rGSP2opt = 1/4*0 + 1/2*0.5 + 1/4* (0.7*0.5 + (0.7*0.5 + 0.3*2/3))

impactGSP2 = rGSP2opt/rGSP20 - 1

% Fourth row

rGSP60 = (.7^4 - .7^5) * (1/7) * 5 + ...
         (.7^3 - .7^4) * (2/7) * 4 + ...
         (.7^2 - .7^3) * (3/7) * 3 + ...
         (.7   - .7^2) * (4/7) * 2 + ...
         (1    - .7  ) * (5/7) * 1

rGSP6opt = (1/2)^6 * ...
           (1*0 + ...
            6*0.5 + ...
            15*(0.5*.7*2 + (0.5 + (1/3)*0.5)*(1-.7)*1 ) + ...
            20*(0.5*.7^2*3 + (0.5 + (1/4)*0.5)*(.7-.7^2)*2 + (0.5 + (2/4)*0.5)*(1-.7)*1 ) + ...
            15*(0.5*.7^3*4 + (0.5 + (1/5)*0.5)*(.7^2-.7^3)*3 + (0.5 + (2/5)*0.5)*(.7-.7^2)*2 + (0.5 + (3/5)*0.5)*(1-.7)*1 ) + ...
            6* (0.5*.7^4*5 + (0.5 + (1/6)*0.5)*(.7^3-.7^4)*4 + (0.5 + (2/6)*0.5)*(.7^2-.7^3)*3 + (0.5 + (3/6)*0.5)*(.7-.7^2)*2 + (0.5 + (4/6)*0.5)*(1-.7)*1 ) + ...
            1* (0.5*.7^5*6 + (0.5 + (1/7)*0.5)*(.7^4-.7^5)*5 + (0.5 + (2/7)*0.5)*(.7^3-.7^4)*4 + (0.5 + (3/7)*0.5)*(.7^2-.7^3)*3 + (0.5 + (4/7)*0.5)*(.7-.7^2)*2 + (0.5 + (5/7)*0.5)*(1-.7)*1 ) ...
            )

impactGSP6 = rGSP6opt/rGSP60 - 1

